﻿using System;
using System.Text;

namespace HslCommunication.Core.IMessage
{
	/// <summary>
	/// 三菱的A兼容1E帧ASCII协议解析规则
	/// </summary>
	// Token: 0x0200015C RID: 348
	public class MelsecA1EAsciiMessage : INetMessage
	{
		/// <inheritdoc cref="P:HslCommunication.Core.IMessage.INetMessage.ProtocolHeadBytesLength" />
		// Token: 0x170005EF RID: 1519
		// (get) Token: 0x06001D6D RID: 7533 RVA: 0x0008D47D File Offset: 0x0008B67D
		public int ProtocolHeadBytesLength
		{
			get
			{
				return 4;
			}
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IMessage.INetMessage.GetContentLengthByHeadBytes" />
		// Token: 0x06001D6E RID: 7534 RVA: 0x0008D5FC File Offset: 0x0008B7FC
		public int GetContentLengthByHeadBytes()
		{
			bool flag = this.HeadBytes[2] == 53 && this.HeadBytes[3] == 66;
			int result;
			if (flag)
			{
				result = 4;
			}
			else
			{
				bool flag2 = this.HeadBytes[2] == 48 && this.HeadBytes[3] == 48;
				if (flag2)
				{
					int num = Convert.ToInt32(Encoding.ASCII.GetString(this.SendBytes, 20, 2), 16);
					bool flag3 = num == 0;
					if (flag3)
					{
						num = 256;
					}
					switch (this.HeadBytes[1])
					{
					case 48:
						result = ((num % 2 == 1) ? (num + 1) : num);
						break;
					case 49:
						result = num * 4;
						break;
					case 50:
					case 51:
						result = 0;
						break;
					default:
						result = 0;
						break;
					}
				}
				else
				{
					result = 0;
				}
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IMessage.INetMessage.CheckHeadBytesLegal(System.Byte[])" />
		// Token: 0x06001D6F RID: 7535 RVA: 0x0008D6C8 File Offset: 0x0008B8C8
		public bool CheckHeadBytesLegal(byte[] token)
		{
			bool flag = this.HeadBytes != null;
			return flag && this.HeadBytes[0] - this.SendBytes[0] == 8;
		}

		/// <inheritdoc cref="M:HslCommunication.Core.IMessage.INetMessage.GetHeadBytesIdentity" />
		// Token: 0x06001D70 RID: 7536 RVA: 0x00047BE1 File Offset: 0x00045DE1
		public int GetHeadBytesIdentity()
		{
			return 0;
		}

		/// <inheritdoc cref="P:HslCommunication.Core.IMessage.INetMessage.HeadBytes" />
		// Token: 0x170005F0 RID: 1520
		// (get) Token: 0x06001D71 RID: 7537 RVA: 0x0008D6FF File Offset: 0x0008B8FF
		// (set) Token: 0x06001D72 RID: 7538 RVA: 0x0008D707 File Offset: 0x0008B907
		public byte[] HeadBytes { get; set; }

		/// <inheritdoc cref="P:HslCommunication.Core.IMessage.INetMessage.ContentBytes" />
		// Token: 0x170005F1 RID: 1521
		// (get) Token: 0x06001D73 RID: 7539 RVA: 0x0008D710 File Offset: 0x0008B910
		// (set) Token: 0x06001D74 RID: 7540 RVA: 0x0008D718 File Offset: 0x0008B918
		public byte[] ContentBytes { get; set; }

		/// <inheritdoc cref="P:HslCommunication.Core.IMessage.INetMessage.SendBytes" />
		// Token: 0x170005F2 RID: 1522
		// (get) Token: 0x06001D75 RID: 7541 RVA: 0x0008D721 File Offset: 0x0008B921
		// (set) Token: 0x06001D76 RID: 7542 RVA: 0x0008D729 File Offset: 0x0008B929
		public byte[] SendBytes { get; set; }
	}
}
